<template>
	<view class="order" v-if="order">
		<view class="top">
			<view class="top_t">
				商品信息
			</view>
			<view class="top_content" >
				<view class="c_left">
					<view class="l_img">
						<image v-if="order.ticket.image" :src="http + order.ticket.image" mode=""></image>
					</view>
				</view>
				<view class="c_right">
					<view class="l_text">
						<view class="text_top">
							{{order.ticket.title}}
						</view>
						<view class="text_bottom">
							{{order.spec}}
						</view>
					</view>
					<view class="">
						<view class="c_money">
							<text>￥</text>{{order.oneprice}}
						</view>
						<view class="c_num">
							<text>x</text>{{order.number}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="msg">
			<view class="msg_list">
				<view class="m_left">
					出行日期
				</view>
				<view class="m_right">
					{{order.daytime}}
				</view>
			</view>
			<view class="msg_list">
				<view class="m_left">
					联系人
				</view>
				<view class="m_right">
					{{order.contactname}}
				</view>
			</view>
			<view class="msg_list">
				<view class="m_left">
					联系电话
				</view>
				<view class="m_right">
					{{order.contactphone}}
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="b_box">
				<view class="b_money">
					订单金额：<text>￥{{order.allprice}}</text>
				</view>
				<view class="b_btn" @click="toPay">
					立即预定
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1,
				order_id: 0,
				mid: 0,
				order: '',
				http: this.$httpimg,
			}
		},
		onLoad(o) {
			this.order_id = o.order_id
			if (uni.getStorageSync('user')) {
				this.mid = uni.getStorageSync('user').id
			}
			this.$post('user/ticketOrderDetail', {
				mid: this.mid,
				order_id: this.order_id
			}).then(res => {
				if (res.code == 0) {
					this.order = res.data
				}
				if (res.code == -3) {
					uni.showToast({
						title: '用户不存在请重新登录',
						icon: 'none',
						mask: true
					})
					uni.clearStorage()
					setTimeout(() => {
						uni.switchTab({
							url: 'index'
						})
					}, 1200)
				}
				if (res.code == -4) {
					uni.showToast({
						title: '用户已被禁用',
						icon: 'none',
						mask: true
					})
					// uni.clearStorage()
					setTimeout(() => {
						uni.switchTab({
							url: 'index'
						})
					}, 1200)
				}
			})

		},
		onShareAppMessage(e) {
			return {
				title: '',
				path: '/pages/index/index'
			}
		},
		methods: {
			toPay() {
				if(this.order.status == 2){
					uni.switchTab({
						url:'/pages/mine/mine'
					})
					return
				}
				
				this.$post('user/ticketOrderPayV2', {
					mid: this.mid,
					order_id: this.order_id
				}).then(res => {
					if (res.code == 0) {
						// let data = JSON.parse(res.data.Rtn_Par_Data)
						let data = res.data.acc_resp_fields
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: data.time_stamp,
							nonceStr: data.nonce_str,
							package: data.package,
							signType: data.sign_type,
							paySign: data.pay_sign,
							success: (res) => {
								uni.hideLoading()
								uni.showToast({
									title: '支付成功',
									mask: true
								})
								uni.switchTab({
									url:'/pages/mine/mine'
								})
							},
							fail: (err) => {
								uni.hideLoading()
								uni.showToast({
									title: '取消支付',
									icon: 'none'
								})
								uni.redirectTo({
									url:`/pages/mine/details?id=${this.order_id}`
								})
							}
						});
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f7f7f7;
	}

	.order {
		image {
			width: 100%;
			height: 100%;
		}

		.bottom {
			position: fixed;
			bottom: 0;
			z-index: 10;
			background-color: #FFFFFF;
			width: 100%;
			height: 150rpx;
			box-sizing: border-box;
			padding: 30rpx;
			padding-bottom: constant(safe-area-inset-bottom);
			/*兼容 IOS<11.2*/
			padding-bottom: env(safe-area-inset-bottom);

			/*兼容 IOS>11.2*/
			.b_box {
				width: 100%;
				height: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.b_money {
					font-size: 32rpx;
					color: #333333;
					font-weight: 500;

					text {
						font-size: 36rpx;
						font-weight: 700;
						color: #FF7416;
					}
				}

				.b_btn {
					width: 292rpx;
					height: 80rpx;
					line-height: 80rpx;
					opacity: 1;
					background: #FF7416;
					border-radius: 40rpx;
					text-align: center;
					color: #333333;
					font-size: 30rpx;
					font-weight: 500;
					color: #FFFFFF;
				}
			}
		}

		.top {
			background-color: #FFFFFF;
			padding: 24rpx 34rpx;

			.top_t {
				font-size: 26rpx;
				font-weight: 700;
				color: #333333;
			}

			.top_content {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;
				.c_left {
					display: flex;
					align-items: center;
					.l_img {
						width: 160rpx;
						height: 136rpx;
					}
				}
				.c_right {
					color: #333333;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.l_text {
						margin-left: 14rpx;
						color: #333333;
					
						.text_top {
							font-size: 28rpx;
							font-weight: 700;
						}
					
						.text_bottom {
							color: #888888;
							font-size: 22rpx;
							margin-top: 20rpx;
						}
					}
					.c_money {
						width: 100%;
						font-size: 26rpx;
						text {
							font-size: 22rpx;
						}
					}

					.c_num {
						width: 100%;
						margin-top: 10rpx;
						font-size: 34rpx;
						text-align: right;
						text {
							font-size: 30rpx;
						}
					}
				}
			}
		}

		.msg {
			background-color: #FFFFFF;
			margin-top: 12rpx;
			padding: 0rpx 34rpx;

			.msg_list {
				padding-top: 32rpx;
				padding-bottom: 32rpx;
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #f5f5f5;

				.m_left {
					width: 150rpx;
					font-size: 26rpx;
					color: #666666;
					font-weight: 500;
				}

				.m_right {
					font-size: 24rpx;
					font-weight: 700;
					color: #333333;
				}
			}
		}
	}
</style>